import time, os, sqlite3
from threading import Thread
import numpy as np
import pandas as pd
from tqsdk import TqApi, TqAuth, TqKq
from rich.console import Console
from rich.theme import Theme
from MyTT import REF, EMA, SUM
import logging

# 新增函数：获取 config 表所有配置项
def get_all_configs():
    """
    从 config 表中获取所有配置项，以字典形式返回
    :return: 包含所有配置项的字典
    """
    try:
        conn = sqlite3.connect('../trade_monitor.db')
        cursor = conn.cursor()
        cursor.execute("SELECT key, value FROM config")
        results = cursor.fetchall()
        conn.close()
        return dict(results)
        #return results
    except Exception as e:
        console.print(f"从数据库获取所有配置项时出错: {e}", style="error")
        return {}
if __name__ == '__main__':
    configs=get_all_configs()
    print(configs)
    print(configs["open_auto"])
    print(configs.get("open_auto"))
    print(configs.get('open_auto', 'on'))
    #如果字典中没有该键，则返回一个默认值：on
    print(configs.get('open_auto_null', 'on'))